Load libraries

library(tidyverse) # data manipulation
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggpubr) # producing data exploratory plots
library(modelsummary) # descriptive data
## `modelsummary` 2.0.0 now uses `tinytable` as its default table-drawing
##   backend. Learn more at: https://vincentarelbundock.github.io/tinytable/
## 
## Revert to `kableExtra` for one session:
## 
##   options(modelsummary_factory_default = 'kableExtra')
##   options(modelsummary_factory_latex = 'kableExtra')
##   options(modelsummary_factory_html = 'kableExtra')
## 
## Silence this message forever:
## 
##   config_modelsummary(startup_message = FALSE)

Import data

df_adults <- read_csv("resp_results_adults.csv")
df_jresp <- read_csv("resp_results_juveniles.csv")

Data manipulation

Adults

df_adults_cleaned <- df_adults |> 
  mutate(FISH_ID = factor(FISH_ID), 
         Sex = factor(Sex), 
         Population = factor(Population), 
         Tank = factor(Tank), 
         Chamber = factor(Chamber), 
         System =factor(System), 
         Temperature =factor(Temperature), 
         True_resting=factor(True_resting)) 

df_males <- df_adults_cleaned |> 
  filter(Sex == "M")
df_females <- df_adults_cleaned |> 
  filter(Sex == "F")

df_adults_cleaned2 <- df_males |> 
  full_join(select(df_females, c("Tank","Temperature","Mass","Resting","Max","AAS","FISH_ID","Sex")), by="Tank") |> 
  mutate(Temperature.x = coalesce(Temperature.x, Temperature.y), 
         FISH_ID.x = coalesce(FISH_ID.x, FISH_ID.y),
         Sex.x = coalesce(Sex.x, Sex.y),
         Resting.midpoint = (Resting.x+Resting.y)/2, 
         Max.midpoint = (Max.x+Max.y)/2, 
         AAS.midpoint = (AAS.x+AAS.y)/2) 

Juveniles

df_jresp$Population <-  fct_collapse(df_jresp$Population, 
                                      `Vlassof cay`= c("Vlassof reef", "Vlassof", "Vlassof Cay", "Vlassof cay"), 
                                      `Arlington reef` = c("Arlington reef","Arlginton reef")) 

df_jresp$Female <-  fct_collapse(df_jresp$Female, 
                                  `CARL359`= c("CARL359", "CARL59")) 


df_jresp2 <-  df_jresp |> 
  unite("F0", c("Male","Female"), sep="_", remove=FALSE) |>
  mutate(across(1:7, factor), 
         Temperature = factor(Temperature), 
         True_resting = factor(True_resting)) 

#df_jresp2_rest <- df_jresp2 |> 
  #filter(True_resting == "Y")

Merging dataframes

temp1a <- df_jresp2 |> 
  mutate(FISH_ID.x = Male)
temp1b <- df_jresp2 |> 
  mutate(FISH_ID.y = Female)
temp2a <- temp1a |> 
  left_join(select(df_adults_cleaned2, c("FISH_ID.x",
                                          "Sex.x",
                                          "Resting.x", 
                                          "Max.x", 
                                          "AAS.x", 
                                          "Mass.x")), 
                    by="FISH_ID.x")
temp2b <- temp1b |> 
  left_join(select(df_adults_cleaned2, c("FISH_ID.y",
                            "Sex.y",
                            "Resting.y", 
                            "Max.y", 
                            "AAS.y", 
                            "Mass.y")), 
                   by="FISH_ID.y") 
df_merged <- temp2a |> 
  left_join(select(temp2b, c("Clutch","Replicate", 
                             "FISH_ID.y",
                             "Resting.y", 
                             "Max.y", 
                             "AAS.y", 
                             "Mass.y")), 
            by=c("Clutch","Replicate"))
df <- df_merged |> 
  mutate(Resting_MALE =Resting.x, 
         Max_MALE =Max.x, 
         AAS_MALE =AAS.x, 
         Mass_MALE =Mass.x, 
         FISH_ID.y =FISH_ID.x,#makes more sense for males to be .y instead of .x
         FISH_ID.x =FISH_ID.x, 
         Resting_FEMALE =Resting.y, 
         Max_FEMALE =Max.y, 
         AAS_FEMALE =AAS.y, 
         Mass_FEMALE =Mass.y) |> 
  mutate(Resting_MID =(Resting_MALE+Resting_FEMALE)/2, 
         Max_MID =(Max_MALE+Max_FEMALE)/2, 
         AAS_MID =(AAS_MALE+AAS_FEMALE)/2) # easier to do it again

Exploratory analysis

Offspring-Male

plot1 <- ggplot(df, aes(x=Resting_MALE, y=Resting, color=Temperature)) + 
  stat_smooth(method = "lm") +
  geom_point(alpha=0.1) + 
  ggtitle("Offspring-male relationship") + 
  xlab("") + 
  ylab("Resting (parental-male)") +
  theme_classic() + 
  theme(legend.position = 'none')

plot2 <- ggplot(df, aes(x=Max_MALE, y=Max, color=Temperature)) + 
  stat_smooth(method = "lm") +
  geom_point(alpha=0.1) + 
  ggtitle("Offspring-male relationship") +
  xlab("") + 
  ylab("Max (parental-male)") +
  theme_classic() + 
  theme(legend.position = 'none')

plot3 <- ggplot(df, aes(x=AAS_MALE, y=AAS, color=Temperature)) + 
  stat_smooth(method = "lm") +
  geom_point(alpha=0.1) + 
  ggtitle("Offspring-male relationship") +
  xlab("") + 
  ylab("AAS (parental-male)") +
  theme_classic() + 
  theme(legend.position = 'none')

plot4 <- ggplot(df, aes(x=Resting_MALE, y=Resting, color=Temperature)) + 
  stat_smooth(method = "lm") +
  #geom_point(alpha=0.1) + 
  ggtitle("Offspring-male relationship") + 
  xlab("Resting (offspring)") + 
  ylab("Resting (parental-male)") +
  theme_classic() + 
  theme(legend.position = "bottom")

plot5 <- ggplot(df, aes(x=Max_MALE, y=Max, color=Temperature)) + 
  stat_smooth(method = "lm") +
  #geom_point(alpha=0.1) + 
  ggtitle("Offspring-male relationship") +
  xlab("Max (offspring)") + 
  ylab("Max (parental-male)") +
  theme_classic() + 
  theme(legend.position = 'none')

plot6 <- ggplot(df, aes(x=AAS_MALE, y=AAS, color=Temperature)) + 
  stat_smooth(method = "lm") +
  #geom_point(alpha=0.1) + 
  ggtitle("Offspring-male relationship") +
  xlab("AAS (offspring)") + 
  ylab("AAS (parental-male)") +
  theme_classic() + 
  theme(legend.position = 'none') 

ggarrange(plot1, plot2, plot3, 
          plot4, plot5, plot6,
          ncol = 3, 
          nrow = 3)

Offspring-Female

plot1 <- ggplot(df, aes(x=Resting_FEMALE, y=Resting, color=Temperature)) + 
  stat_smooth(method = "lm") +
  geom_point(alpha=0.1) + 
  ggtitle("Offspring-female relationship") + 
  xlab("") + 
  ylab("Resting (parental-female)") +
  theme_classic() + 
  theme(legend.position = 'none')

plot2 <- ggplot(df, aes(x=Max_FEMALE, y=Max, color=Temperature)) + 
  stat_smooth(method = "lm") +
  geom_point(alpha=0.1) + 
  ggtitle("Offspring-female relationship") +
  xlab("") + 
  ylab("Max (parental-female)") +
  theme_classic() + 
  theme(legend.position = 'none')

plot3 <- ggplot(df, aes(x=AAS_FEMALE, y=AAS, color=Temperature)) + 
  stat_smooth(method = "lm") +
  geom_point(alpha=0.1) + 
  ggtitle("Offspring-female relationship") +
  xlab("") + 
  ylab("AAS (parental-female)") +
  theme_classic() + 
  theme(legend.position = 'none')

plot4 <- ggplot(df, aes(x=Resting_FEMALE, y=Resting, color=Temperature)) + 
  stat_smooth(method = "lm") +
  #geom_point(alpha=0.1) + 
  ggtitle("Offspring-female relationship") + 
  xlab("Resting (offspring)") + 
  ylab("Resting (parental-female)") +
  theme_classic() + 
  theme(legend.position = "bottom")

plot5 <- ggplot(df, aes(x=Max_FEMALE, y=Max, color=Temperature)) + 
  stat_smooth(method = "lm") +
  #geom_point(alpha=0.1) + 
  ggtitle("Offspring-female relationship") +
  xlab("Max (offspring)") + 
  ylab("Max (parental-female)") +
  theme_classic() + 
  theme(legend.position = 'none')

plot6 <- ggplot(df, aes(x=AAS_FEMALE, y=AAS, color=Temperature)) + 
  stat_smooth(method = "lm") +
  #geom_point(alpha=0.1) + 
  ggtitle("Offspring-female relationship") +
  xlab("AAS (offspring)") + 
  ylab("AAS (parental-female)") +
  theme_classic() + 
  theme(legend.position = 'none') 

ggarrange(plot1, plot2, plot3, 
          plot4, plot5, plot6,
          ncol = 3, 
          nrow = 3)

Offspring-Midpoint

plot1 <- ggplot(df, aes(x=Resting_MID, y=Resting, color=Temperature)) + 
  stat_smooth(method = "lm") +
  geom_point(alpha=0.1) + 
  ggtitle("Offspring-midpoint relationship") + 
  xlab("") + 
  ylab("Resting (parental-midpoint)") +
  theme_classic() + 
  theme(legend.position = 'none')

plot2 <- ggplot(df, aes(x=Max_MID, y=Max, color=Temperature)) + 
  stat_smooth(method = "lm") +
  geom_point(alpha=0.1) + 
  ggtitle("Offspring-midpoint relationship") +
  xlab("") + 
  ylab("Max (parental-midpoint)") +
  theme_classic() + 
  theme(legend.position = 'none')

plot3 <- ggplot(df, aes(x=AAS_MID, y=AAS, color=Temperature)) + 
  stat_smooth(method = "lm") +
  geom_point(alpha=0.1) + 
  ggtitle("Offspring-midpoint relationship") +
  xlab("") + 
  ylab("AAS (parental-midpoint)") +
  theme_classic() + 
  theme(legend.position = 'none')

plot4 <- ggplot(df, aes(x=Resting_MID, y=Resting, color=Temperature)) + 
  stat_smooth(method = "lm") +
  #geom_point(alpha=0.1) + 
  ggtitle("Offspring-midpoint relationship") + 
  xlab("Resting (offspring)") + ylab("Resting (parental-midpoint)") +
  theme_classic() + 
  theme(legend.position = 'none')

plot5 <- ggplot(df, aes(x=Max_MID, y=Max, color=Temperature)) + 
  stat_smooth(method = "lm") +
  #geom_point(alpha=0.1) + 
  ggtitle("Offspring-midpoint relationship") +
  xlab("Max (offspring)") + ylab("Max (parental-midpoint)") +
  theme_classic() + 
  theme(legend.position = 'none')

plot6 <- ggplot(df, aes(x=AAS_MID, y=AAS, color=Temperature)) + 
  stat_smooth(method = "lm") +
  #geom_point(alpha=0.1) + 
  ggtitle("Offspring-midpoint relationship") +
  xlab("AAS (offspring)") + ylab("AAS (parental-midpoint)") +
  theme_classic() + 
  theme(legend.position = 'none') 

ggarrange(plot1, plot2, plot3, 
          plot4, plot5, plot6,
          ncol = 3, 
          nrow = 3, 
          common.legend = TRUE)

Descriptive statistics

Juveniles - overview

Overview

tinytable_zq9tvpd7qh0l4mvlg0mf
Population 27 28.5 30
Arlington reef 60 43 53
Pretty patches 26 21 34
Sudbury reef 27 15 16
Vlassof cay 26 10 28
datasummary(Factor(F0) ~ Factor(Temperature), 
            data = df, 
            fmt = "%.0f")
tinytable_5spjngkbdzfd66suqflr
F0 27 28.5 30
CARL217_CARL226 0 8 0
CARL218_CARL222 0 0 13
CARL230_CARL235 14 0 0
CARL233_CARL215 0 0 8
CARL237_CARL219 10 0 0
CARL241_CARL239 15 0 0
CARL249_CARL360 0 0 16
CARL335_CARL359 0 14 0
CARL338_CARL345 0 8 0
CARL344_CARL370 0 0 16
CARL354_CARL355 21 0 0
CARL367_CARL363 0 7 0
CARL369_CARL349 0 6 0
CPRE189_CPRE202 0 0 15
CPRE372_CPRE209 14 0 0
CPRE375_CPRE377 12 0 0
CPRE391_CPRE390 0 0 6
CPRE447_CPRE452 0 0 13
CPRE453_CPRE459 0 7 0
CPRE521_CPRE524 0 7 0
CPRE550_CPRE533 0 7 0
CSUD002_CSUD213 0 8 0
CSUD009_CSUD212 14 0 0
CSUD013_CSUD017 13 0 0
CSUD016_CSUD078 0 7 0
CSUD312_CSUD304 0 0 16
CVLA089_CVLA059 0 0 7
CVLA098_CVLA049 0 10 0
CVLA102_CVLA466 6 0 0
CVLA106_CVLA091 0 0 15
CVLA468_CVLA477 13 0 0
CVLA486_CVLA463 7 0 0
CVLA498_CVLA493 0 0 6

Juveniles

Resting oxygen uptake

tinytable_kpklcd8rr5psqy9or6dk
Temperature NUnique mean median min max sd Histogram
27 135 0.21 0.21 0.08 0.64 0.07 ▃▆▇▅▁▁
28.5 89 0.23 0.23 0.09 0.47 0.08 ▂▄▆▆▇▄▁▁ ▁
30 131 0.23 0.23 0.06 0.40 0.07 ▁▂▃▆▇▅▆▄▁▁

Maximum oxygen uptake

tinytable_w5b35g2hldqvya4wzpsz
Temperature NUnique mean median min max sd Histogram
27 132 0.58 0.55 0.27 1.66 0.19 ▄▇▆▃▁
28.5 85 0.65 0.64 0.24 1.08 0.18 ▂▄▇▇▇▃▃▂▂
30 130 0.65 0.64 0.16 1.29 0.19 ▂▃▇▅▆▃▁

Absolute aerobic scope

tinytable_lh1jl9y6p5rotk7411fw
Temperature NUnique mean median min max sd Histogram
27 128 0.37 0.34 0.14 1.02 0.14 ▃▇▇▄▃▂
28.5 85 0.42 0.39 0.10 0.79 0.15 ▁▃▅▇▄▃▅▃▁▁
30 130 0.42 0.41 0.09 0.99 0.15 ▁▄▆▅▇▃▁

Adults - overview

Overview

datasummary(Factor(Population) ~ Factor(Temperature), 
            data = df_adults_cleaned, 
            fmt = "%.0f")
tinytable_hv8m6eqklcc8ib3z2wij
Population 27 28.5 30
Arlington reef 8 7 4
Pretty patches 4 6 4
Sudbury reef 4 3 2
Vlassof cay 6 2 5
datasummary(Factor(Population) ~ Factor(Temperature)*Factor(Sex), 
            data = df_adults_cleaned, 
            fmt = "%.0f")
tinytable_xaboosza4uol8q3nt4ze
27 28.5 30
Population F M F M F M
Arlington reef 4 4 2 5 2 2
Pretty patches 2 2 3 3 3 1
Sudbury reef 2 2 1 2 1 1
Vlassof cay 3 3 1 1 3 2

Pairs

datasummary(Factor(Population)*Factor(Temperature.x) ~ AAS.midpoint*(NUnique), 
            data = df_adults_cleaned2, 
            fmt = "%.0f")
tinytable_b1i0m4zaocbbr94uwanb
Population Temperature.x NUnique
Arlington reef 27 3
28.5 2
30 2
Pretty patches 27 2
28.5 3
30 1
Sudbury reef 27 2
28.5 2
30 1
Vlassof cay 27 3
28.5 1
30 2

Adults

Resting oxygen uptake

tinytable_042jw5mg5f43nu4j12w2
Temperature NUnique mean median min max sd Histogram
27 22 6.29 6.06 3.82 10.09 1.56 ▂▂▃▇▂▂▁▁▁▁
28.5 18 6.49 6.96 4.35 8.49 1.45 ▇▂▅▂▃▃▅▃
30 15 7.29 7.20 5.14 9.15 1.46 ▅▂▇▂▂▂▇▇

Maximum oxygen uptake

tinytable_lbjq7jokld2zg95izoye
Temperature NUnique mean median min max sd Histogram
27 22 16.58 16.91 9.70 22.06 3.36 ▃▃▅▅▃▃▅▇▂
28.5 18 17.09 17.23 11.04 28.39 3.94 ▅▂▅▇▇▃▂
30 15 16.48 16.83 11.78 21.24 2.82 ▂▃▂▃▇▂▂▃▂

Absolute aerobic scope

tinytable_h7396qddygd7297248qz
Temperature NUnique mean median min max sd Histogram
27 22 10.29 10.26 3.85 16.28 3.14 ▃▁▄▇▃▆▃▃▁
28.5 18 10.59 9.66 6.11 20.44 3.66 ▅▅▇▇▃▂▂
30 15 9.19 9.16 4.36 12.77 2.91 ▃▂▅▂▂▂▃▇